import { defineStore } from 'pinia'

export const baseToolsStore = defineStore('baseTools', {
  state: () => {
    return {
      isDepartment: false, //是否是集团部门
      departmentInfo: {
        departmentcode: '',
        departmentnamecn: '集团职能',
        departmentnameen: '',
      },
      groupLeft: true, //左侧组模块是否显示
      groupRight: true, //右侧组模块是否显示
    }
  },

  actions: {
    setIsDepartment(isDepartment: boolean) {
      this.isDepartment = isDepartment
    },
    setDepartmentInfo(departmentInfo: Object) {
      this.departmentInfo = departmentInfo
    },
    setGroupLeft(groupLeft: boolean) {
      this.groupLeft = groupLeft
    },
    setGroupRight(groupRight: boolean) {
      this.groupRight = groupRight
    },

    clear() {
      this.isDepartment = false
      this.departmentInfo = {
        departmentcode: '',
        departmentnamecn: '集团职能',
        departmentnameen: '',
      }
      this.groupLeft = true
      this.groupRight = true
    },
  },
  // 持久化
  persist: {
    enabled: true, // 是否开启持久化
  },
})
// 如果是开发环境，可以在控制台直接访问baseToolsStore，方便调试。
if (process.env.NODE_ENV === 'development') {
  window['_BASE_STORE'] = baseToolsStore
}
